﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using AdmLaboratorios.Business;
using AdmLaboratorios.DTO;

namespace AdmLaboratorios
{
    public partial class frmPartnerConsulta : Form
    {
        public PartnerDTO Partner { get; set; }


        public frmPartnerConsulta()
        {
            InitializeComponent();
        }

        private void frmPartnerConsulta_Load(object sender, EventArgs e)
        {
            gv.DataSource = Recepcion.Partners();
        }

        private void txPartner_TextChanged(object sender, EventArgs e)
        {
            gv.DataSource = null;
            gv.DataSource = Partners.PartnersFiltered(txPartner.Text);
        }

        private void btAceptar_Click(object sender, EventArgs e)
        {
            Seleccionar();
        }

        private void Seleccionar()
        {
            if (gv.SelectedRows.Count == 1)
            {
                Partner = Partners.Get(Convert.ToInt32(gv.SelectedRows[0].Cells["Id"].Value));

                this.Close();
                this.DialogResult = System.Windows.Forms.DialogResult.OK;
            }
            else
            {
                MessageBox.Show("Puede seleccionar tan solo un Partner.",
                    "Atención", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }

        private void button2_Click(object sender, EventArgs e)
        {
            this.Close();
            this.DialogResult = System.Windows.Forms.DialogResult.Cancel;
        }

        private void gv_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
        {
            Seleccionar();
        }

        private void frmPartnerConsulta_Shown(object sender, EventArgs e)
        {
            txPartner.Focus();
        }
    }
}
